import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    userInfo: uni.getStorageSync('userInfo') || {},
  }),

  getters: {
    // 获取用户信息
    getUserInfo: (state) => state.userInfo,
  },

  actions: {
    // 设置用户信息
    setUserInfo(info) {
      this.userInfo = info
      uni.setStorageSync('userInfo', info)
    },

    // 更新用户信息
    updateUserInfo(info) {
      this.userInfo = { ...this.userInfo, ...info }
      uni.setStorageSync('userInfo', this.userInfo)
    },
  }
})